<extend name="Base/common" />
<block name="style">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Api/css/order.css">
</block>
<block name="Content">

<div class="page-group">
    <div class="page page-current">
        <div class="content login">
            <form action="" class="m-phone">
                <ul>
                    <li>
                        <i class="icon-number"></i>
                        <input type="text" name="tel" id="tel" placeholder="请输入账号" value="{$tel}">
                        <div class="delete right">&nbsp;</div>
                    </li>
                    <li>
                        <i class="icon-pwd"></i>
                        <input type="password" name="pwd" id="pwd" placeholder="请输入密码">
                        <input type="hidden" name="historyURL" id="historyURL" value="{$historyURL}"/>
                        <div class="delete right">&nbsp;</div>
                    </li>
                    <li class="code" id="verifyli" <if condition="$display eq '1'"><else/>style="display:none;"</if>>
                        <i class="icon-valid"></i>
                        <input type="text" name="verify" id="verify" placeholder="请输入验证码">
                        <img class="right" src="{:U('Public/verify')}" id="verifybtn">
                    </li>
                </ul>
                <div class="pwd">
                    <label><input type="checkbox" name="remember" id="remember" value="1"><span>记住账号</span></label>
                    <a class="forget right" href="{:U('register', 'type=2')}">忘记密码?</a>
                </div>
                <div class="confirm">
                    <a class="button button-fill button-big" type="button" onclick="login()">登录</a>
                </div>
            </form>
            <div class="login-item">
                <a href="{:U('register')}">点此注册</a>
            </div>
        </div>
    </div>
</div>

</block>

<block name="script">
<script src="__PUBLIC__/Api/js/order.js" type="text/javascript"></script>
<script type="text/javascript">
	
//刷新验证码
var verifyimg = $('#verifybtn').attr("src");

$("#verifybtn").click(function(){

    if (verifyimg.indexOf('?') > 0) {

        $("#verifybtn").attr("src", verifyimg + '&random=' + Math.random());
    }else {

        $("#verifybtn").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
    }
});

function login(){
	
	var tel = $.trim($("#tel").val()) || "";
	var pwd = $.trim($("#pwd").val()) || "";
	var verify = $.trim($("#verify").val()) || "";
	var remember = $("#remember").attr("checked");
	remember = remember ? '1' : '0';
	
	if(!(/^1((3|4|5|8){1}\d{1}|70)\d{8}$/.test(tel))){ 
        $.alert("账号格式有误，请确认");  
        return false; 
    } 

	if(pwd.length == 0){
		$.alert('请输入密码');
		return false;
	}else if($("#verifyli").css("display") != 'none' && verify.length == 0){
		$.alert('请输入验证码');
		return false;
	}
	
	var target = Think.U('Public/login');
	
	$.post(target, {'tel':tel, 'pwd':pwd, 'remember':remember, 'verify':verify}, function(dataObj){
		
		if(dataObj.status == '-1'){
			
			if(dataObj.times){
				$("#verifyli").show();
			}
			
			$.alert("帐号或密码错误");
		}else if(dataObj.status == '-201'){
			$("#verifyli").show();
			$.alert('请输入验证码');
		}else if(dataObj.status == '-202'){
			$.alert('验证码错误');
		}else{
			var historyURL = $("#historyURL").val();
			historyURL = historyURL ? historyURL : Think.U('Index/index');
			window.location.href = historyURL;
		}
	});
}

</script>
</block>

